/**
 * Window for Introduction screen
 * @author Team Love is Like Sand
 * @version 1.0
 *
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * Intro window
 * @author kushagramansingh
 * @version 1.0
 */
public class IntroWindow {
	
	/**
	 * The backing frame for the view
	 */
	private JFrame frmSpaceTrader;
	
	/**
	 * The controller for the view
	 */
	private IntroController control;
	
	/**
	 * Load state
	 */
	private boolean loaded;
	
	/**
	 * Game loaded state
	 */
	private int state;
	
	/**
	 * Constructor of class that creates the application.
	 */
	public IntroWindow(){
		initialize();
		loaded = false;
	}

	/**
	 * Initializes the contents of the frame.
	 */
	private void initialize(){
		frmSpaceTrader = new JFrame();
		frmSpaceTrader.setTitle("Space Trader");
		control = new IntroController();
		frmSpaceTrader.setVisible(true);
		
		frmSpaceTrader.setBounds(100, 100, 600, 425);
		frmSpaceTrader.setResizable(false);
		frmSpaceTrader.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmSpaceTrader.getContentPane().setLayout(null);
		
		JLabel lblWelcomeToSpacetrader = new JLabel("WELCOME TO SPACETRADER");
		lblWelcomeToSpacetrader.setForeground(Color.WHITE);
		lblWelcomeToSpacetrader.setFont(new Font("Arnprior", Font.PLAIN, 24));
		lblWelcomeToSpacetrader.setBounds(115, 46, 366, 34);
		frmSpaceTrader.getContentPane().add(lblWelcomeToSpacetrader);
		
		JButton btnNewGame = new JButton("New Game");
		btnNewGame.addActionListener(new NewGameListener());
		btnNewGame.setBounds(93, 317, 109, 23);
		frmSpaceTrader.getContentPane().add(btnNewGame);
		
		JButton btnLoadSave = new JButton("Load Game");
		btnLoadSave.addActionListener(new LoadListener(this));
		btnLoadSave.setBounds(378, 317, 103, 23);
		frmSpaceTrader.getContentPane().add(btnLoadSave);
		
		ImageIcon icon = new ImageIcon("Images/Galaxy.jpg");
		JLabel picture = new JLabel(icon);
		picture.setBounds(0, 0, 600, 450);
		frmSpaceTrader.getContentPane().add(picture);
	}
	
	/**
	 * Checks if it is loaded or not
	 * @return loaded
	 */
	public boolean isLoaded(){
		return loaded;
	}
	
	/**
	 * Sets loaded variable
	 * @param b
	 */
	public void setLoaded(boolean b){
		loaded = b;
	}
	
	/**
	 * Returns state
	 * @return state
	 */
	public int getState(){
		return state;
	}
	
	/**
	 * Returns the player of the controller
	 * @return control.getPlayer()
	 */
	public Player getPlayer(){
		return control.getPlayer();
	}
	
	/**
	 * Returns the universe of the controller
	 * @return control.getUniverse()
	 */
	public Universe getUniverse(){
		return control.getUniverse();
	}
	
	/**
	 * Listener for new games
	 * @author Team Love is Like Sand
	 * @version 1.0
	 *
	 */
	private class NewGameListener implements ActionListener{
		
		/**
		 * Performs action for listener
		 * @param event 
		 */
		public void actionPerformed(ActionEvent event){
			loaded = true;
			state =0;
			frmSpaceTrader.dispose();
		}
	}
	
	/**
	 * Listener for loading
	 * @author Team Love is Like Sand
	 * @version 1.0
	 *
	 */
	private class LoadListener implements ActionListener{
		
		/**
		 * Window that contains load button
		 */
		private IntroWindow window;
		
		/**
		 * Constructor for LoadListner that initializes instance variables
		 * @param window
		 */
		private LoadListener(IntroWindow window){
			this.window = window;
		}
		
		/**
		 * If the window can load it changes states.
		 * @param event
		 */
		public void actionPerformed(ActionEvent event){
			if(control.canLoad(window)){
				frmSpaceTrader.dispose();
				state = 1;
			}
		}
	}
}

